package cn.zyzpp.service.resume.impl;

import cn.zyzpp.dao.EducationalDao;
import cn.zyzpp.entity.resume.Educational;
import cn.zyzpp.service.resume.EducationalService;
import cn.zyzpp.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

/**
 * Create by yster@foxmail.com 2018/5/21/021 22:37
 */
@Service
@CacheConfig(cacheNames = {"EducationalService"})
public class EducationalServiceImpl implements EducationalService {
    @Autowired
    private EducationalDao educationalDao;

    @Override
    @CacheEvict(allEntries = true)
    public void save(Educational educational, int uid) {
        educational.setUid(uid);
        educational.setMajorCourse(StringUtil.symline(educational.getMajorCourse()));
        educationalDao.save(educational);
    }

    @Override
    @Transactional
    @CacheEvict(allEntries = true)
    public void delect(int id) {
        educationalDao.deleteAllById(id);
    }

    @Override
    @Transactional
    @CacheEvict(allEntries = true)
    public void updataByUid(Educational educational) {
        Educational educational1 = educationalDao.findByUid(educational.getUid());
        educational1.updata(educational1);
    }

    @Override
    @Cacheable(key = "targetClass + methodName +#p0")
    public Educational query(int uid) {
        return educationalDao.findByUid(uid);
    }

    @Override
    @Cacheable(key = "targetClass + methodName +#p0")
    public List<Educational> queryAll(int uid) {
        return educationalDao.findAllByUid(uid);
    }
}
